import * as types from './type';

const state = () => {
    return {
        // 当前缓存的日期
        curDate: JSON.parse(sessionStorage.getItem('currentDate')) || {startTime: Date.parse(new Date()), type: 1}
    }
};
const getters = {
  curDate: state => state.curDate
};

const actions = {
  saveDate ({commit}, data) {
    sessionStorage.setItem('currentDate', JSON.stringify(data));
    commit(types.SAVE_DATE, data);
  },
  clearDate ({commit}) {
    commit(types.SAVE_DATE, '');
    sessionStorage.removeItem('currentDate');
  }
};

const mutations = {
  [types.SAVE_DATE] (state, res) {
    state.curDate = res;
  }
};

export default {
  state,
  actions,
  getters,
  mutations
};
